#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.web.helper;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;

/**
 * Created by well on 16/6/27.
 */
public class RequestHelper {

    private static Logger log = LoggerFactory.getLogger(RequestHelper.class);

    public static Map<String, String> getFormData(HttpServletRequest request) {
        if (request == null) {
            return Collections.emptyMap();
        }

        StringBuilder sb = new StringBuilder();
        try {
            BufferedReader reader = request.getReader();
            int length = request.getContentLength();
            char[] buff = new char[length];
            int len;
            while ((len = reader.read(buff)) != -1) {
                sb.append(buff, 0, len);
            }
        } catch (IOException e) {
            log.error("", e);
        }
        if (sb.length() > 0) {
            Map map = JSON.parseObject(sb.toString(), Map.class);
            if (map == null) {
                return Collections.emptyMap();
            }
            return map;
        }


        return Collections.emptyMap();
    }
}
